package CTRLayer;
import ModelLayer.*;
import DBLayer.*;

public class SalesOrderCtr 
{

	public void insertSalesOrder(int salesID, double totalPrice, String salesDate, 
			String deliveryStatus, String diliveryDate, int empID, int customerID){
		{    
	           SalesOrder salesOrderObj = new SalesOrder();
	        
	           salesOrderObj.setSalesID(salesID);
	           salesOrderObj.setPrice(totalPrice);
	           salesOrderObj.setSalesDate(salesDate);
	           salesOrderObj.setDeliveryStatus(deliveryStatus);
	           salesOrderObj.setDeliveryDate(diliveryDate);
			   salesOrderObj.setCustomer(new SalesOrder(customerID));
	           salesOrderObj.setEmployee(new SalesOrder(empID));
	         	    
	           try{
	            DbConnection1.startTransaction();
	            DBSalesOrder dbSales = new DBSalesOrder();
	            dbSales.insertSalesOrder(salesOrderObj);
	            DbConnection1.commitTransaction();
	           }
	           catch(Exception e)
	           {
	               DbConnection1.rollbackTransaction();
	           }
		}
	}
	public void removeSalesOrder(int orderID) {
		DBSalesOrder dbSales = new DBSalesOrder();
		dbSales.delete(orderID);
	}
	
	public SalesOrder findEmployee(int orderID) {
		DBSalesOrder dbSales = new DBSalesOrder();
		SalesOrder result = dbSales.findSalesOrder(orderID, false);
		return result;
	}
 
	public int updateEmployee(String date, String deliverydate,
			String deliveryStatus) {
		DBSalesOrder dbSales = new DBSalesOrder();
		SalesOrder sale = new SalesOrder();
		sale.setSalesDate(date);
		sale.setDeliveryDate(deliverydate);
		sale.setDeliveryStatus(deliveryStatus);
		return dbSales.updateSalesOrder(sale);
	}
}
